using System;
using System.Collections.Generic;

namespace 表单批量填写器
{
    /// <summary>
    /// 表单数据模型 - 对应 httpbin.org/forms/post 表单
    /// </summary>
    public class FormDataModel
    {
        /// <summary>
        /// 客户姓名 (input[name="custname"])
        /// </summary>
        public string CustomerName { get; set; }

        /// <summary>
        /// 电话号码 (input[name="custtel"])
        /// </summary>
        public string Telephone { get; set; }

        /// <summary>
        /// 电子邮件 (input[name="custemail"])
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// 披萨尺寸 (radio[name="size"]) - 可选值: small, medium, large
        /// </summary>
        public string PizzaSize { get; set; }

        /// <summary>
        /// 披萨配料 (checkbox[name="topping"]) - 可选值: bacon, cheese, onion, mushroom
        /// 多个配料用逗号分隔，例如: "bacon,cheese"
        /// </summary>
        public string PizzaToppings { get; set; }

        /// <summary>
        /// 配送时间 (input[name="delivery"]) - 格式: HH:mm
        /// </summary>
        public string DeliveryTime { get; set; }

        /// <summary>
        /// 配送说明 (textarea[name="comments"])
        /// </summary>
        public string Comments { get; set; }

        /// <summary>
        /// 验证数据有效性
        /// </summary>
        public bool IsValid()
        {
            if (string.IsNullOrWhiteSpace(CustomerName))
                return false;

            if (!string.IsNullOrWhiteSpace(Email) && !Email.Contains("@"))
                return false;

            var validSizes = new[] { "small", "medium", "large" };
            if (!string.IsNullOrWhiteSpace(PizzaSize) && 
                Array.IndexOf(validSizes, PizzaSize.ToLower()) == -1)
                return false;

            return true;
        }

        /// <summary>
        /// 获取配料列表
        /// </summary>
        public List<string> GetToppingsList()
        {
            var list = new List<string>();
            if (!string.IsNullOrWhiteSpace(PizzaToppings))
            {
                var toppings = PizzaToppings.Split(new[] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var topping in toppings)
                {
                    list.Add(topping.Trim().ToLower());
                }
            }
            return list;
        }

        public override string ToString()
        {
            return $"{CustomerName} - {Email} - {PizzaSize}";
        }
    }
}
